//
//  BiaoDescViewController.swift
//  jiaoyi
//
//  Created by wjk on 2018/11/5.
//  Copyright © 2018 wjk. All rights reserved.
//

import UIKit
import SwiftyJSON

class BiaoDescViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var fair_id:String!
    var target_id:String!
    
    var datas:[JSON] = [JSON]()
    
    @IBOutlet weak var tableView: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "标的详情"
        loadData()
        // Do any additional setup after loading the view.
    }
    
    func loadData() -> Void {
        NetWorkRequest(.fairtargets(fair_id: fair_id, target_id: target_id)) { (res) -> (Void) in
            if res["code"] as! String == "000000" {
                let d = jsonFormater(data: res["data"] as Any)
                self.datas.append(JSON(["title":"标的号","subTitle":d["alias"].stringValue]))
                self.datas.append(JSON(["title":"批次","subTitle":d["batch_no"].stringValue]))
                self.datas.append(JSON(["title":"粮食性质","subTitle":d["grain_type_text"].stringValue]))
                self.datas.append(JSON(["title":"委托单位","subTitle":d["client_name"].stringValue]))
                self.datas.append(JSON(["title":"承储库","subTitle":d["depot_ent_name"].stringValue]))
                self.datas.append(JSON(["title":"品种","subTitle":d["variety_name"].stringValue]))
                self.datas.append(JSON(["title":"等级","subTitle":d["grade_text"].stringValue]))
                self.datas.append(JSON(["title":"数量","subTitle":"\(d["num"].stringValue) \(d["num_unit_text"].stringValue)"]))
                self.datas.append(JSON(["title":"底价","subTitle":"\(d["base_price_show"].stringValue) \(d["price_unit_text"].stringValue)"]))
                self.datas.append(JSON(["title":"生产年份","subTitle":"\(d["prod_year"].stringValue) 元"]))
                self.tableView.reloadData()
            }
        }
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.datas.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
        cell.textLabel?.text = self.datas[indexPath.row]["title"].stringValue
        cell.detailTextLabel?.text = self.datas[indexPath.row]["subTitle"].stringValue
        cell.selectionStyle = .none
        return cell
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
